// 引入lodash
const _ = require('lodash')

// console.log(_)

function once(fn){
    let done = false
    return function(){
        if(!done){
            done = true
            fn.apply(this,arguments)
            console.log(this)
            console.log(arguments) // => [Arguments] { '0': 'eating' }
        }
    }
}
let doThing = once(something=>{
    console.log('to '+ something)  // => to eating
})
doThing('eating')

function splat(fn) {
     return function(array) {
         return fn.apply(null, array)
     }
 };
 let sum = splat(function(x, y){ return x + y});
console.log(sum([1,2])); // => 3
//  let sum2 = splat(function(array){
//     return array.reduce(function(total,item){ return total + item})
//  });  // 这是一段错误代码，报错 TypeError: array.reduce is not a function
